<?

if ($DATA['component']['id']) {

	// list editor
	
	$_id_component	= $DATA['component']['id'];			//	list id value
	$_id_data		= D_MB_DATA;			//	meta id value
	$_id_meta		= D_MB_META;			//	meta id value

	$_crit = "id_data=$_id_data AND id_parent=$_id_component";

	$_param			= 'edit';				//	ID param name in the URL, used here & @ template
	$_values			= array('title', 'params');	// which fields are stored in language variations
	
	$_fields = array(
		'title' => array('lang' => true), 
		'params' => array('lang' => true), 
	);
	
	$_bits			= array('required' => 0x01, 'multiple' => 0x02, 'listbox' => 0x04);
	
	
	
	if (($a = (int)param('edit')) && ($DATA['object'] = datafetch('db_item', tb('data'), "$_crit AND id=$a"))) {

		foreach($DATA['langs'] as $lang)
			$DATA['object']['data'][$lang['text']] = datafetch_array('loadmeta', $_id_meta, 
				array('parent' => $a, 'assoc' => $lang['text'], 'getclob' => true));


		$DATA['object']['kind'] = ($DATA['object']['tag'] & 0xff);
		
		$temp = $DATA['object']['tag'] >> 8;
		foreach($_bits as $name => $mask)
			$DATA['object'][$name] = $temp & $mask;


		switch (action(array('editor_save'))) {
		
			case 'editor_save':

				$_record = array('id_data' => $_id_meta, 'id_parent' => $a);
					
				dataset('killmeta', "id_data=$_id_meta AND id_parent=$a");
				dataset('savemeta', prepareModel($_fields, $_record));

				$t = ($temp = trim($_POST['title'][LANG_DEF])) ? $temp : $DATA['object']['data'][LANG_DEF]['title'];

				$temp = 0;
				foreach($_bits as $name => $mask)
					if (postdata($name))
						$temp |= $mask;

				dataset('db_update', tb('data'), array(
					'name' => $t, 
					'value' => trim(strip_tags(postdata('value'))), 
					'tag' => (int)postdata('kind') | ($temp << 8)), 
				"$_crit AND id=$a");
				


				header("Location: "._transformURL($CURRENT->url, array('remove_param' => $_param)));
				exit;
		
				break;
		
		}
	
			
	}
	return false;
	
} else exit;

?>
